<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>日志管理</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=0">
    <link rel="stylesheet" href="/js/layui/css/layui.css" media="all">
</head>
<body style="background:white;padding:10px 15px;overflow:hidden;">
<div id="LAY_app">
    <form class="layui-form" action="" lay-filter="example" style="width: 100%;height:50px;display:flex;align-items:center;margin:30px auto;">
        <div class="layui-form-inline">
            <label class="layui-form-label">时间区间</label>
            <div class="layui-input-inline">
                <input type="text" id="start_time" name="start_time" autocomplete="off" placeholder="请输入开始时间" class="layui-input">
            </div> 至
            <div class="layui-input-inline">
                <input type="text" id="end_time" name="start_time" autocomplete="off" placeholder="请输入结束时间" class="layui-input">
            </div>
        </div>
        <div class="layui-form-item" style="width: 20%;float: left;display: inline;margin-bottom: -5px;padding-left: 2%;">
            <div class="layui-inline" style="display:flex;justify-content:flex-start;">
                <input type="text" id="key" name="title" lay-verify="title" autocomplete="off" placeholder="请输入关键字" class="layui-input">
                <button id="search" type="button" class="layui-btn" lay-filter="search-stu-submit">
                    <i class="layui-icon">&#xe615;</i> 搜索
                </button>
            </div>
        </div>
    </form>
    <table class="layui-hide" id="table" lay-filter="test" style="width:90%;display:block;margin:10px auto;"></table>
</div>

<script type="text/html" id="barDemo">
    <!--<a class="layui-btn layui-btn-xs" lay-event="open">{{# if(d.shijiStatus == "冻结") { }}启用{{# } else { }}冻结{{# } }}</a>-->
    <a class="layui-btn layui-btn-xs" lay-event="agree">通过</a>
    <a class="layui-btn layui-btn-xs" lay-event="disAgree">拒绝</a>
    <!--<a class="layui-btn layui-btn-xs" lay-event="detail">详情</a>-->
    <!--<a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del">删除</a>-->
</script>

<script type="text/html" id="toolbarDemo">
    <!--<div class="layui-btn-container">-->
    <!--<button class="layui-btn layui-btn-sm" lay-event="getCheckData">获取选中行数据</button>-->
    <!--<button class="layui-btn layui-btn-sm" lay-event="getCheckLength">获取选中数目</button>-->
    <!--<button class="layui-btn layui-btn-sm" lay-event="isAll">验证是否全选</button>-->
    <!--</div>-->
</script>

<script src="/js/layui/layui.all.js"></script>
<script src="/admin/js/token.js"></script>

<script>
    var current = 1
    var totals = 0

    layui.use('table', function(){
        var table = layui.table;
        table.render({
            elem: '#table'
            ,id : 'lalala'//重载需要
            ,url:'/log/selectLog'
            //,url:'/admin/tixian/query?status=1'
            ,toolbar: '#toolbarDemo' //开启头部工具栏，并为其绑定左侧模板
            ,defaultToolbar: ['filter', 'exports', 'print', { //自定义头部工具栏右侧图标。如无需自定义，去除该参数即可
                title: '提示'
                ,layEvent: 'LAYTABLE_TIPS'
                ,icon: 'layui-icon-tips'
            }]
                // ,
            // done:function(res, curr, count){
            //     //console.log("laile")
            //     //得到当前页码
            //     current = curr
            //     totals = count
            //     if(totals != 0) {
            //         parent.document.getElementById("dot_sh").innerHTML = "<span class='layui-badge'>"+totals+"</span>"
            //     }
            // }
            ,title: '日志表'
            ,cols: [[
                {field:'', title:'序号',align : 'center', width:'5%', fixed: 'left', type:'numbers'}
                // ,{field:'tixianUser', title:'编号', width:130}
                ,{field:'user',align : 'center', title:'用户名', width:'15%'}
                ,{field:'ip',align : 'center', title:'IP', width:'15%'}
                ,{field:'caozuo',align : 'center', title:'操作名称', width:'19%'}
                ,{field:'url',align : 'center', title:'访问url'}
                ,{field:'caozuoTime',align : 'center', title:'时间'}
                // ,{field:'shenQingTime', title:'申请提现时间', width:200}
                // ,{field:'msg', title:'备注', width:200}
                // ,{field:'status', title:'状态', width:260 , templet:function(d){
                //         //console.log(d)
                //         return d.status == 1 ? "审核通过" : "审核不通过" ;
                //     } }
                // ,{fixed: 'right', title:'操作', toolbar: '#barDemo'}
            ]]
            ,page: true
        });

        //头工具栏事件
        table.on('toolbar(test)', function(obj){
            var checkStatus = table.checkStatus(obj.config.id);
            switch(obj.event){
                case 'getCheckData':
                    var data = checkStatus.data;
                    layer.alert(JSON.stringify(data));
                    break;
                case 'getCheckLength':
                    var data = checkStatus.data;
                    layer.msg('选中了：'+ data.length + ' 个');
                    break;
                case 'isAll':
                    layer.msg(checkStatus.isAll ? '全选': '未全选');
                    break;

                //自定义头工具栏右侧图标 - 提示
                case 'LAYTABLE_TIPS':
                    layer.alert('这是工具栏右侧自定义的一个图标按钮');
                    break;
            };
        });

        var $ = layui.$ ;
        var layer = layui.layer ;

        function isNumber(val) {
            var regPos = /^\d+(\.\d+)?$/; //非负浮点数
            var regNeg = /^(-(([0-9]+\.[0-9]*[1-9][0-9]*)|([0-9]*[1-9][0-9]*\.[0-9]+)|([0-9]*[1-9][0-9]*)))$/; //负浮点数
            if(regPos.test(val) || regNeg.test(val)) {
                return true;
            } else {
                return false;
            }
        }

        //监听行工具事件
        table.on('tool(test)', function(obj){
            var data = obj.data;
            //console.log(obj)
            if(obj.event === 'del'){
                layer.confirm('真的删除行么', function(index){
                    obj.del();
                    layer.close(index);
                });
            }
        });
    });

    //监听提交
    layui.use(['form', 'layedit', 'laydate' , 'jquery'], function() {
        var form = layui.form
            , layer = layui.layer
            , layedit = layui.layedit
            , laydate = layui.laydate
            , $ = layui.$ ;
        form.on('submit(example)', function (data) {
            var key = $("#key").val()
            search(key);
            return false;
        });
    })

    layui.use(['jquery'] , function(){
        $("#search").click(function(){
            var key = $("#key").val();
            var start_time = $("#start_time").val();
            var end_time = $("#end_time").val();
            // if(start_time=="" && end_time==""){
            //
            // }else if(start_time!="" && end_time!=""){
            //
            // }else if(start_time=="" && end_time!=""){
            //     start_time = dangqianshijian()+" "+"00:00:00";
            //     end_time = end_time.substring(0,10).concat(" ","23:59:59");
            // }else if(start_time!="" && end_time==""){
            //     start_time = dangqianshijian()+" "+"00:00:00";
            //     end_time = start_time.substring(0,10).concat(" ","23:59:59");
            // }
            //console.log("姓名："+key+" 开始时间："+start_time+" 结束时间："+end_time);
            search(key,start_time,end_time);
        });

        function dangqianshijian(){
            var date=new Date();
            var year=date.getFullYear();
            var month=date.getMonth()+1;
            var day=date.getDate();
            var hour=date.getHours();
            var minute=date.getMinutes();
            var second=date.getSeconds();

            //这样写显示时间在1~9会挤占空间；所以要在1~9的数字前补零;
            if (month<10) {
                month='0'+month;
            }
            if (day<10) {
                day='0'+day;
            }
            if (hour<10) {
                hour='0'+hour;
            }
            if (minute<10) {
                minute='0'+minute;
            }
            if (second<10) {
                second='0'+second;
            }
            return dqTime = year+'-'+month+'-'+day;
        }

        // $("#timeSearch").click(function(){
        //     var start_time = $("#start_time").val();
        //     var end_time = $("#end_time").val();
        //     //console.log("来啦："+start_time+"  "+end_time);
        //     timeSearch(start_time,end_time);
        // })
    })

    // function timeSearch(start_time,end_time){
    //     layui.use('table', function() {
    //         var table = layui.table;
    //         table.reload('lalala', {
    //             where: {
    //                 start_time: start_time,
    //                 end_time: end_time
    //             },
    //             page: {
    //                 curr: 1
    //             }
    //         });
    //     })
    // $.ajax({
    //     url:"/admin/tixian/selectTiXianTime",
    //     data:{start_time:start_time , end_time:end_time} ,
    //     success:function(res) {
    //         console.log(res)
    //     }
    // })
    // }

    function search(key,start_time,end_time){
        layui.use('table', function() {
            var table = layui.table;
            table.reload('lalala', {
                where: {
                    name: key,
                    start_time: start_time,
                    end_time: end_time
                },
                page: {
                    curr: 1
                }
            });
        })
        // $.ajax({
        //     url:"/guke/gukeList" ,
        //     data:{page:1 , key:key} ,
        //     success:function(res) {
        //         console.log(res)
        //     }
        // })
    }
</script>

<script>
    layui.use('laydate', function(){
        var laydate = layui.laydate;
        var endDate= laydate.render({
            elem: '#end_time',//选择器结束时间
            type: 'datetime',
            min:"1970-1-1",//设置min默认最小值
            done: function(value,date){
                startDate.config.max={
                    year:date.year,
                    month:date.month-1,//关键
                    date: date.date,
                    hours: 0,
                    minutes: 0,
                    seconds : 0
                }
            }
        });
        //日期范围
        var startDate=laydate.render({
            elem: '#start_time',
            type: 'datetime',
            max:"2099-12-31",//设置一个默认最大值
            done: function(value, date){
                endDate.config.min ={
                    year:date.year,
                    month:date.month-1, //关键
                    date: date.date,
                    hours: 0,
                    minutes: 0,
                    seconds : 0
                };
            }
        });
    });
</script>
</body>
